<template>
	<view class="wanl-money">
		<cust-header title="我的钱包">
			<template v-slot:header>
				<view class="header"></view>
			</template>
			<view class="header headerBac u-flex-col wrap u-row-center">

				<none-navbar></none-navbar>
				<view class="u-flex u-row-center" @tap="$wanlshop.to('/pages/user/money/list')">
					<view class="all-wrap u-flex-col u-row-center u-col-center">
						<view class="price">{{user.total_balance}}</view>
						<view class="desc">余额(元)</view>
					</view>
				</view>
				<view class="split-wrap u-flex u-row-between u-row-around">
					<view class="split-item u-flex-col u-row-center u-col-center">
						<view class="price">{{user.current_balance}}</view>
						<view class="desc">可提现(元)</view>
					</view>

					<view class="split-item u-col-center u-flex">
						<view class="u-flex-col u-col-center">

							<view class="price">{{user.freeze_balance}}</view>

							<view class="desc u-rela">
								<view>冻结金(元)</view>
								<u-icon name="info-circle" color="#ffff00" @click="showFreeze" class="u-abso u-m-l-14"
									style="left: 100%;bottom: 0;top: 0;"></u-icon>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="wrap u-m-t-16">
				<view class="border-wrap">
					<u-cell-item icon="" title="账单明细" hover-class=""
						@click="$wanlshop.to('/pages/user/money/list?type=0')">
						<template v-slot:icon>
							<image src="https://img.aibbyp.com/wechat/images/me/bills.png" mode="widthFix" class="icon">
							</image>
						</template>
					</u-cell-item>
					<u-cell-item icon="" title="邀请提佣" hover-class=""
						@click="$wanlshop.to('/pages/user/money/list?type=1')">
						<template v-slot:icon>
							<image src="https://img.aibbyp.com/wechat/images/me/share.png" mode="widthFix" class="icon">
							</image>
						</template>
					</u-cell-item>
				</view>
			</view>
			<view class="balance_button">
				<view v-if="userInfo.level == 2" class="content balance_button_item balance_button_item_left"
					@click="balanceEdit('withdrawral')">
					<text>提现</text>
				</view>
				<view class="content balance_button_item" style="background-color: #FF4530;color: aliceblue;"
					@click="balanceEdit('recharge')">
					<text>充值</text>
				</view>
			</view>
		</cust-header>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				userInfo: {},
				user: {},
				freeze: '0.00',
				// 缺省页图片,如果有数据则将该属性取消
				list_item_area: '',
				dataList: [],
				reload: false, //判断是否上拉
				total: 0, //数据量
				current_page: 1, //当前页码
				last_page: 1, //总页码
				status: 'more',
				contentText: {
					contentdown: ' ',
					contentrefresh: '加载中',
					contentnomore: ''
				},
				no_more_text: '',
			};
		},
		computed: {
			// ...mapState(['user'])
		},
		onLoad() {
			// this.getList();
			this.userInfo = uni.getStorageSync('wanlshop:user')
		},
		onShow() {
			this.loadData();
		},
		onPullDownRefresh() {
			this.current_page = 1;
			this.reload = true;
			this.getList();
		},
		onNavigationBarButtonTap(e) {
			this.$wanlshop.to("/pages/user/bank/bank")
		},
		onReachBottom() {
			//判断是否最后一页
			if (this.current_page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				this.current_page = this.current_page + 1; //页码+1
				this.status = 'loading';
				this.getList();
			}
		},
		methods: {
			async loadData() {
				this.$api.post({
					url: '/jmy/user/balance',
					success: res => {
						console.log('余额', res)
						this.user = res
						this.$store.commit('user/setUserInfo', res);
					}
				});
			},
			balanceEdit(event) {
				if (event == 'recharge') {
					this.$wanlshop.to('/pages/user/money/recharge')
				} else if (event == 'withdrawral') {
					this.$wanlshop.to('/pages/user/money/withdraw')
				}
			},

			showFreeze() {
				uni.showModal({
					content: '冻结资金为转介绍分佣金额，须转介绍用户确认收货后，7个工作日方可解冻，转为可用金额。',
					showCancel: false
				})
			},
			changeBtnStyle() {
				console.log('123456');
			},
			async getList() {
				this.$api.post({
					url: '/wanlshop/pay/moneyLog',
					data: {
						page: this.current_page
					},
					success: res => {
						uni.stopPullDownRefresh();
						this.dataList = this.reload ? res.data : this.dataList.concat(res.data); //数据 追加
						this.total = res.total; //数据量
						this.current_page = res.current_page; //当前页码
						this.last_page = res.last_page; //总页码
						this.status = res.total == 0 ? 'noMore' : 'more';
						if (this.current_page == res.last_page) {
							this.no_more_text = '没有更多了'
						}
						if (this.dataList.length == 0) {
							this.list_item_area = 'list_item_area';
							this.no_more_text = '暂无数据'
						}
					}
				});
			},
			toMoney(item) {
				this.$wanlshop.to(`/pages/user/money/details?data=${JSON.stringify(item)}`);
			}
		},
	};
</script>

<style lang="scss" scoped>
	.headerBac {
		background: #2979ff;
		padding-bottom: 40rpx;
	}

	.wanl-money .title {
		color: rgba(255, 255, 255, .7);
	}

	.balance_title {
		height: 500upx;
		width: 100%;
		padding: 0 4%;
		/* border-radius: 15px; */
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
		align-content: center;
		background-image: url("https://img.aibbyp.com/wechat/images/bg.png");
		background-position: right bottom, left top;
		background-repeat: repeat;
		background-size: cover;
	}

	.balance_dec {
		font-size: 15px;
		font-weight: 500;
		line-height: normal;
		letter-spacing: 0em;
		font-feature-settings: "kern" on;
		color: #E5E5E5;
		margin-top: 20%;
	}

	.money {
		font-size: 40px;
		font-weight: bold;
		line-height: normal;
		letter-spacing: 0em;
		font-feature-settings: "kern" on;
		color: #FFFFFF;
	}

	.all_banlance {
		width: auto;
		height: 50upx;
		margin-top: -20px;
		background: rgba(255, 255, 255, 0.36);
		border-radius: 38px;
		padding-left: 5%;
		padding-right: 5%;
		line-height: 50upx;
		font-family: Source Han Sans;
		font-size: 13px;
		font-weight: normal;
		letter-spacing: 0em;
		color: #E5E5E5
	}

	.balance_button {
		position: absolute;
		bottom: 0;
		width: 100%;
		height: 80upx;
		display: flex;
		flex-direction: row;
		margin-bottom: 60rpx;
	}

	.balance_button_item {
		flex: 1;
		text-align: center;
		line-height: 80upx;
		font-family: 思源黑体;
		font-size: 16px;
		font-weight: normal;
		line-height: 80upx;
		letter-spacing: 0em;
		font-feature-settings: "kern" on;
		color: #333333;
	}

	.balance_button_item_left {
		border-right: 0.8px solid #F0F0F0;
		background: #CCCCCC;
	}

	.list-area {
		width: 100%;
		margin-top: -200upx;
		padding: 0 4%;
		position: absolute;
		bottom: 100upx;
		top: 500upx;
	}

	.list {
		width: 100%;
		height: 100%;
		background-color: #FFFFFF;
		border-radius: 10px;
		padding: 4%;
		display: flex;
		flex-direction: column;
		overflow: scroll;
	}

	.list_title {
		display: flex;
		flex-direction: row;
	}

	.list_title_dec {
		width: 95%;
		font-size: 15px;
		font-weight: 500;
		line-height: normal;
		letter-spacing: 0em;
		font-family: Source Han Sans;
		font-feature-settings: "kern" on;
		color: #333333;
	}

	.list_item {
		width: 100%;
		height: 69px;
		border-bottom: 1px solid #F5F5F5;
		margin-top: 20upx;
		display: flex;
		flex-direction: row;
	}

	.list_item_left {
		display: flex;
		flex-direction: column;
		width: 60%;
		padding: 4% 0;
	}

	.list_item_left_dec {
		font-family: Source Han Sans;
		font-size: 14px;
		font-weight: 500;
		line-height: normal;
		letter-spacing: 0em;
		font-feature-settings: "kern" on;
		color: #656565;
		z-index: 0;
	}

	.list_item_left_time {
		margin-top: 6px;
		font-family: Source Han Sans;
		font-size: 12px;
		font-weight: normal;
		line-height: normal;
		letter-spacing: 0em;
		font-feature-settings: "kern" on;
		color: #999999;
		z-index: 1;
	}

	.list_item_right {
		margin-left: 25%;
		line-height: 69px;
		font-family: Source Han Sans;
		font-size: 20px;
		font-weight: normal;
		letter-spacing: 0em;
		font-feature-settings: "kern" on;
		color: #00C10A;
	}

	.list_item_area {
		background-image: url("https://img.aibbyp.com/wechat/images/test.png");
		/* background-position: right bottom, left top; */
		background-repeat: no-repeat;
		background-size: 100%;
		height: 350upx;
		width: 350upx;
		margin: 0 auto;
		margin-top: 80upx;
	}

	.all-wrap,
	.split-wrap {
		.price {
			height: 86rpx;
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 700;
			font-size: 60rpx;
			color: #FFFFFF;
			line-height: 86rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.desc {
			height: 34rpx;
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 400;
			font-size: 24rpx;
			color: #CCCCCC;
			line-height: 34rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}
	}

	.split-wrap {
		.price {
			height: 58rpx;
			font-family: Source Han Sans, Source Han Sans;
			font-weight: 500;
			font-size: 40rpx;
			color: #E5E5E5;
			line-height: 58rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}
	}
</style>

<style lang="scss" scoped>
	::v-deep .border-wrap {
		.u-cell {
			padding-left: 0;
			padding-right: 0;
		}
	}

	.border-wrap {
		.icon {
			width: 24rpx;
			height: 24rpx;
			margin-right: 14rpx;
		}
	}
</style>